<?php
  
  
  class upload_file {
  
  
  
      public $inputField;
      public $path;
      public $overwrite = false;
      public $newFilename = "";
      public $baseDir = false;
      
      
      
      
      
      
  
  // eigene Class?????????????
    function saveUploadFile()
        {
            

        //echo "field:$inputField-------";

        //print_r($_FILES);

        //global $rootDir;

        // falls kein Datei Name Ã¼bergeben wurde, der Datei Name des Uploaded Files wird genommen
        //if ($filename == "")
        $filename=$_FILES[$this->inputField]['name'];

        //echo $filename;

        //$filenameOrginal=$filename;
        $filenameOrginal=file::getFilename($filename);
        //echo $filenameOrginal;
        //print_r($_FILES);


        // fÃ¼r was war das???????????????
        //$path = str_replace($filenameOrginal, "", $filename);

        //$newFilename    =$path. "/". convert::convertFilename($filename);
        //$newFilename = $filename;
        $newFilename=  $this->path ."/" .$filename;


        // falls bestehendes File nicht Ã¼berschrieben werden soll
        if ($this->overwrite === false)
            {
            $n=0;

            //do {
            while (file::fileExists($newFilename, $this->baseDir))
                {
                //file_exists($sysFilename) === TRUE)

                //            echo $i;
                $n++;
                //$uploadfileOrginal=$_FILES[$datafield]['name'];

                // to do
                // version am ende des filename

                $filename="v" . $n . "_" . $filenameOrginal;
                $filename="v" . $n . "_" . convert::convertFilename($filenameOrginal);
                $newFilename=config::$basePath. $this->path . $filename;
                //$uploadfile=$uploaddir . $fileName;
                //$uploadfile=$uploaddir ."v" . $y . "_" . $uploadfileOrginal;


                //            $uploadfile=$uploaddir . $uploadfile;
                }
            }

        $sysFilename= $newFilename;  
        
        if ($this->baseDir) {
            $sysFilename=config::$basePath . $newFilename;
        }
        
        //echo $_FILES[$inputField]['tmp_name'];
        //echo $sysFilename;

        if (move_uploaded_file($_FILES[$this->inputField]['tmp_name'], $sysFilename))
            {

            //echo "ok";

            }
        else
            {

            // funktioniert auch mit fehlermeldung
            echo "error beim upload der datei..." . $_FILES[$this->inputField]['tmp_name'] . " nach " . $filename;
            }

        return $newFilename;
        }
  
  
  }
  
  
  
  
  
?>
